import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/store";
import cookies from "vue-cookies";
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: () => import('../components/HomeView.vue')
  },
  {
    path: '/openMap',
    component: () => import('../components/OpenMapView.vue')
  },
]

const router = new VueRouter({
  routes
})


//全局前置路由守卫————初始化的时候、每次路由切换之前被调用
router.beforeEach((to, from, next) => {
  let isIn = cookies.get("isIn");
  console.log(isIn)
  if (to.path === "/home" || isIn === "True") {
    next();
  } else {
    localStorage.clear();
    if (from.path !== "/home") {
      router.replace("/home");
    }
    alert("请选择工作空间和图层")
  }
});



export default router
